package com.stylefeng.guns.modular.ds.warpper;

import com.stylefeng.guns.common.constant.state.ChannelLevel;
import com.stylefeng.guns.common.constant.state.ChannelStatus;
import com.stylefeng.guns.common.constant.state.EnumCommon;
import com.stylefeng.guns.core.base.warpper.BaseControllerWarpper;

import java.util.List;
import java.util.Map;


/**
 * 多数据源Demo-Bean转换器
 *
 * @author fengshuonan
 * @Date 2018-06-17 18:18:53
 */
public class ChannelInfoWarpper extends BaseControllerWarpper {

    public ChannelInfoWarpper(List<Map<String, Object>> list) {
        super(list);
    }

    @Override
    protected void warpTheMap(Map<String, Object> map) {
        String status = EnumCommon.valueByKey(ChannelStatus.class, map.get("status"));
        Integer oldStatus = (Integer) map.get("status");
        if (ChannelStatus.DISABLE.getKey() == oldStatus) {
            status = "<div style=\"color:#ff0000\">" + status + "</div>";
        } else if (ChannelStatus.ENABLE.getKey() == oldStatus) {
            status = "<div style=\"color:#00ff00\">" + status + "</div>";
        }
        map.put("statusFormat", status);
        map.put("status", EnumCommon.valueByKey(ChannelStatus.class, map.get("status")));
        map.put("level", EnumCommon.valueByKey(ChannelLevel.class, map.get("level")));

//        String searchUrl = (String) map.get("searchUrl");
//        if (searchUrl.contains("https://")) {
//            searchUrl = "https://" + searchUrl.split("https://")[1].split("/")[0];
//        } else if (searchUrl.contains("http://")) {
//            searchUrl = "http://" + searchUrl.split("http://")[1].split("/")[0];
//        }
        map.put("nameFormat", "<a href=\"" + map.get("detailUrl") + "\" target=\"_blank\">" + map.get("name") + "</a>");
    }
}